from pages.base_page import BasePage

class TopicPage(BasePage):
    top_title = '//*[@resource-id="cool.dingstock.mobile:id/common_titlebar_title_tv"]'
    end_prompt = '//*[@text="- The end -"]'
    back_button = '//*[@resource-id="cool.dingstock.mobile:id/common_titlebar_left_icon"]'
    test_topic = '//*[@text="2.8.0话题测试"]'
    first_trend_body = '//*[@resource-id="cool.dingstock.mobile:id/home_fragment_second_rv"]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]'
    trend_detail_topic = '//*[@resource-id="cool.dingstock.mobile:id/topic_title_tv"]'
    
    def swipe_topic(self):
        """滑动话题到最右侧，点击"""
        self.swipe_position((0.917, 0.185), (0.082, 0.182))
        self.swipe_position((0.917, 0.185), (0.082, 0.182))
        
    def get_top_title(self):
        """获取顶部title"""
        return self.get_xpath_text(self.top_title)
    
    def swipe_topic_list(self):
        """滑动话题列表到底部，获取底部提示文案"""
        self.swipe_position((0.518, 0.889),(0.532, 0.12))
        self.swipe_position((0.518, 0.889),(0.532, 0.12))
        return self.get_xpath_text(self.end_prompt)
    
    def go_back(self):
        """点击返回"""
        self.click_xpath(self.back_button)
        
    def click_test_topic(self):
        """点击测试话题：2.8.0话题测试"""
        self.click_xpath(self.test_topic)
        
    def get_test_topic_content(self):
        """获取测试话题名称"""
        return self.get_xpath_text(self.test_topic)
    
    def get_first_trend_detail_topic(self):
        """进入第一个测试话题动态，获取动态话题名称"""
        self.click_xpath(self.first_trend_body)
        return self.get_xpath_text(self.trend_detail_topic)
        